package com.hns.can.report.web;

import com.hns.can.common.domain.GridPage;
import com.hns.can.common.vo.CommonParamsVo;
import com.hns.can.common.web.BaseController;
import com.hns.can.mainte.vo.BatteryStatusVo;
import com.hns.can.report.entity.TBsStatProbAnaEntity;
import com.hns.can.report.service.CarQuestionAnlsService;
import com.hns.can.report.vo.CarProblemAnalysisVo;
import com.hns.can.report.vo.QualityIndexParamVo;
import com.hns.frame.mybatis.Pagination;
import com.hns.tool.export.ExportUtil;
import com.hns.tool.pub.DateTool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

import java.net.URLEncoder;
import java.util.Arrays;
import java.util.List;

/**
 * 车辆问题分析控制类
 *
 * @author:zhangzq
 * @email:
 * @version Revision 2.0.0
 */
@Controller
@RequestMapping("/carQuestionAnls")
public class CarQuestionAnlsController extends BaseController {

    final private String[] headerNames = new String[]{"企业名称","营运线路","车牌号","日期（天）","在线率问题","里程问题","能耗问题","故障问题","行为问题","报站问题"};
    final private String[] headerFields = new String[]{"corpName", "lineName", "licPltNo", "reportDate", "onlineProbAna", "mileProbAna", "enerConsProbAna", "mftProbAna", "bhvProbAna", "stnProbAna"};


    @Autowired
    private CarQuestionAnlsService carQuestionAnlsService;

    /**
     * 分页查询车辆问题
     * @param vo
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
    @RequestMapping("/searchTBsStatProbAnaPage")
    @ResponseBody
    public Object searchTBsStatProbAnaPage(QualityIndexParamVo vo) throws Exception {
        Pagination page = carQuestionAnlsService.searchTBsStatProbAnaPage(vo);
        GridPage grid = new GridPage(page);
        return this.getReturnResult(grid);
    }

    /**
     * 导出车辆问题Pdf文件
     * @param vo
     * @param response
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
    @RequestMapping("/exportTBsStatProbAnaPdf")
    public void exportTBsStatProbAnaPdf(QualityIndexParamVo vo, HttpServletResponse response) throws Exception {
        List<TBsStatProbAnaEntity> list = list = carQuestionAnlsService.searchTBsStatProbAnaList(vo);
        ExportUtil.exportFiles(Arrays.asList(headerNames), Arrays.asList(headerFields), list, response, "pdf", URLEncoder.encode("车辆问题数据分析", "UTF-8")+DateTool.getCurrentSysDate("yyyyMMddHHmmss"), "车辆问题数据");
    }
    
    /**
     * 导出车辆问题excel文件
     * @param vo
     * @param response
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
    @RequestMapping("/exportTBsStatProbAnaExcel")
    public void exportTBsStatProbAnaExcel(QualityIndexParamVo vo, HttpServletResponse response) throws Exception {
        List<TBsStatProbAnaEntity> list = list = carQuestionAnlsService.searchTBsStatProbAnaList(vo);
        ExportUtil.exportFiles(Arrays.asList(headerNames), Arrays.asList(headerFields), list, response, "excel", URLEncoder.encode("车辆问题数据分析", "UTF-8")+DateTool.getCurrentSysDate("yyyyMMddHHmmss"), "车辆问题数据");
    }
    
    /**
     * 车辆问题分析统计信息
     * @param vo
     * @return
     * @throws Exception
     */
    @RequestMapping("/getCarProblemPage")
    @ResponseBody
    public Object getCarProblemList(QualityIndexParamVo vo) throws Exception{
//    	Pagination page = carQuestionAnlsService.getCarProblemPage(vo);
    	List<CarProblemAnalysisVo> list = carQuestionAnlsService.getCarProblemPage(vo);
//        GridPage grid = new GridPage(page);
        return this.getReturnResult(list);
    }
}
